package com.chinaunicom.create.singleton.hungry;

import java.util.Random;

/**
 * @author liry
 * @version 1.0
 * @date Created on 2022/7/14 14:22
 * Description: 懒汉式(静态内部类)
 */
public class HSingleton05 {

    private HSingleton05() {
    }

    private static class SingletonInstance{
        private static final HSingleton05 instance = new HSingleton05();
    }

    public static HSingleton05 getInstance(){
        return  SingletonInstance.instance;
    }
    


    public static void main(String[] args) {
        Random random = new Random();
        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
//                       Thread.sleep(random.nextInt(100));
                        System.out.println(HSingleton05.getInstance().toString());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
            }, "Thread name: " + i).start();
        }

    }
}
